/*
 * Created on Jan 25, 2004
 *
 * To change the template for this generated file go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
package org.vectrics.swing;


import java.util.Iterator;
import java.util.Vector;
import java.util.List;
import javax.swing.JComponent;


public class Row {
	private Vector cells = new Vector();
	private int height = 22;

	private TablePanel owner = null;

	public Row(TablePanel owner) {
		super();
		this.owner = owner;
	}

	protected TablePanel getTable() {
		return(this.owner);
	}
	
	protected int getCellIndex(Cell cell) {
		int column = this.cells.indexOf(cell);
		return(column);
	}
	
	protected int getColumnStart(Cell cell) {
		int cellIndex = getCellIndex(cell);
		int column = 0;
		for (int i = 0; i < cellIndex; i++) {
			Cell curCell = (Cell)getCells().get(i);
			column += curCell.getColSpan();
		}
		return(column);
	}
		
	protected int getColumnLeft(int column) {
		return(this.owner.getColumnLeft(column));
	}
	
	
	public List getCells() {
		return(cells);
	}

	public Cell addCell() {
		Cell cell = new Cell(this.owner, this);
		cells.add(cell);
		return(cell);
	}

	public Cell addCell(JComponent component) {
		Cell cell = addCell();
		cell.setComponent(component);
		cell.setComponentPosition();
		return(cell);
	}
	
	public int getTotalCellSpan() {
		int totalColSpan = 0;
		Iterator iter = cells.iterator();
		while (iter.hasNext()) {
			Cell cell = (Cell)iter.next();
			totalColSpan += cell.getColSpan();
		}
		return(totalColSpan);
	}

	
	public int getHeight() {
		return height;
	}

	public void setHeight(int height) {
		this.height = height;
	}

}
